package analyzers;

import java.io.IOException;
import java.io.StringReader;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.br.BrazilianAnalyzer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.util.Version;

public class TextAnalyzer {
	private static BrazilianAnalyzer analyzer = new BrazilianAnalyzer(
			Version.LUCENE_34);

	public static void main(String[] args) {
try {
	System.out.println(analyze("não sei nao ein bom ruimm demaisss"));
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
	}

	public static String analyze(String text) throws IOException {
		StringReader sr = new StringReader(text);

		TokenStream tokenStream = analyzer.tokenStream(null, sr);
		CharTermAttribute charTermAttribute = tokenStream
				.getAttribute(CharTermAttribute.class);

		StringBuilder sb = new StringBuilder("");
		String term;
		while (tokenStream.incrementToken()) {
			term = charTermAttribute.toString();
			sb.append(term).append(" ");
		}
		return sb.toString();
	}
}